use hypers::prelude::*;
use hypers::tokio;
use serde::Deserialize;

#[allow(dead_code)]
#[derive(Debug, Deserialize)]
struct User {
    #[serde(rename = "@name")]
    name: String,
}
#[allow(dead_code)]
async fn xml(mut req: Request) -> Result<String> {
    let user = req.parse_body::<User>().await?;
    Ok(format!("welcome {}!", user.name))
}
#[tokio::test]
async fn test() -> Result<()> {
    let mut root = Router::default();
    root.post("/xml", xml); // http://127.0.0.1:7878/
    let cli = hypers::TestClient::new(root);
    let mut res = cli.post("http://127.0.0.1:7878/xml")
        .header(hypers::hyper::header::CONTENT_TYPE, "application/xml")
        .body(r#"<User name="foo"/>"#)
        .send()
        .await;
    assert_eq!(res.take_string().await?, "welcome foo!".to_owned());
    Ok(())
}
fn main() {}
